﻿@model BackEnd.Models.ImageWhatWeDoModel
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script>
    function ValidateData()
    {
        $.ajax({
            url: '/ImageWhatWeDo/Create',
            type: 'POST',
            data: {                
                imageArtist: $('#iphFileNameImageArtist').val(),
                redirectUrlArtist: $('#RedirectUrlArtist').val(),
                imageArtPrice: $('#iphFileNameImageArtPrice').val(),
                redirectUrlArtPrice: $('#RedirectUrlArtPrice').val(),
                imageAuctionCalendar: $('#iphFileNameImageAuctionCalendar').val(),
                redirectUrlAuctionCalendar: $('#RedirectUrlAuctionCalendar').val()
            },
            success: function (data) {
                switch (data) {
                    case -1:
                        window.location("/Account/Login");
                        break;
                    case -2:
                        window.location("/Account/Login");
                        break;
                    default:
                        alert('Insert Success!');
                }
            }
        });
    }

    function RemoveFileUpload(spanId, type, fileName) {
        $("#" + spanId).remove();
        switch (type) {
            case 1:
                $('#RedirectUrlArtist').val('');
                $("#iphFileNameImageArtist").val('');                
                break;
            case 2:
                $('#RedirectUrlArtPrice').val('');
                $("#iphFileNameImageArtPrice").val('');                
                break;
            case 3:
                $('#RedirectUrlAuctionCalendar').val('');
                $("#iphFileNameImageAuctionCalendar").val('');                
                break;
        }
    }    
</script>
<h2>Image What We Do</h2>
<table>    
    <tr>
        <td>@Html.LabelFor(m=>m.ImageArtist)</td>
        <td>
            <input type="file" id="ipfImageArtist"/>            
                <script type="text/javascript"> 
                    

                    $('#ipfImageArtist').uploadify({
                    'script': '/ImageWhatWeDo/UploadFile',
                    'uploader': '/Scripts/uploadify/uploadify.swf',
                    'buttonImg': '/Scripts/uploadify/btn_select.png',
                    'cancelImg': '/Scripts/uploadify/cancel.png',
                    'folder': '/SlideShow',
                    'width': '51',
                    'height': '23',
                    'fileExt': '*.jpg;*.gif;*.png;',
                    'fileDesc': '*.jpg;*.gif;*.png;',
                    'sizeLimit': '52428800',
                    'queueSizeLimit': 10,
                    'multi': false,
                    'auto': true,
                    'scriptData': { RequireUploadifySessionSync: true, SecurityToken: UploadifyAuthCookie, SessionId: UploadifySessionId },
                    'onQueueFull': function (event, queueID, fileObj) {
                    },
                    'onSelect': function (event, queueID, fileObj) {
                    },
                    'onError': function (event, queueID, fileObj, obj) {                        
                    },
                    'onProgress': function (event, queueID, fileObj, obj) {
                    },
                    'onComplete': function (event, queueID, fileObj, response, data) {
                        var json = eval("(" + response + ")");
                        if (json.errorCode == 100) {
                            $('#iphFileNameImageArtist').val(json.fileName);
                            var spanId = json.fileName.replace(/\./gi, "_");
                            var str = "<span id=" + spanId + ">" + json.fileName + "<br/><input type='text' name='RedirectUrlArtist' id='RedirectUrlArtist' /> (<a href=javascript:RemoveFileUpload('" + spanId + "',1,'" + json.fileName + "')>Xóa</a>)</span><br/>";
                            $("#fileQueueImageArtist").html(str);
                        } else {                            
                        }
                    },
                    'onAllComplete': function () {
                    }
                });
            </script>
            <div id="fileQueueImageArtist"> 
                @if (!string.IsNullOrEmpty(Model.ImageArtist))
                {               
                    <span id="@Model.ImageArtist.Replace(".","_")">@Model.ImageArtist<br/><input type="text" name="RedirectUrlArtist" id="RedirectUrlArtist" value="@Model.RedirectUrlArtist" /> (<a href="javascript:RemoveFileUpload('@Model.ImageArtist.Replace(".","_")',1,'@Model.ImageArtist')">Xóa</a>)</span><br />                
                }
            </div>
        </td>
    </tr>
    <tr>
        <td>@Html.LabelFor(m=>m.ImageArtPrice)</td>
        <td>
            <input type="file" id="ipfImageArtPrice"/>            
                <script type="text/javascript">
                    $('#ipfImageArtPrice').uploadify({
                        'script': '/ImageWhatWeDo/UploadFile',
                        'uploader': '/Scripts/uploadify/uploadify.swf',
                        'buttonImg': '/Scripts/uploadify/btn_select.png',
                        'cancelImg': '/Scripts/uploadify/cancel.png',
                        'folder': '/SlideShow',
                        'width': '51',
                        'height': '23',
                        'fileExt': '*.jpg;*.gif;*.png;',
                        'fileDesc': '*.jpg;*.gif;*.png;',
                        'sizeLimit': '52428800',
                        'queueSizeLimit': 10,
                        'multi': false,
                        'auto': true,
                        'scriptData': { RequireUploadifySessionSync: true, SecurityToken: UploadifyAuthCookie, SessionId: UploadifySessionId },
                        'onQueueFull': function (event, queueID, fileObj) {
                        },
                        'onSelect': function (event, queueID, fileObj) {
                        },
                        'onError': function (event, queueID, fileObj, obj) {
                        },
                        'onProgress': function (event, queueID, fileObj, obj) {
                        },
                        'onComplete': function (event, queueID, fileObj, response, data) {
                            var json = eval("(" + response + ")");
                            if (json.errorCode == 100) {
                                $('#iphFileNameImageArtPrice').val(json.fileName);
                                var spanId = json.fileName.replace(/\./gi, "_");
                                var str = "<span id=" + spanId + ">" + json.fileName + "<br/><input type='text' name='RedirectUrlArtPrice' id='RedirectUrlArtPrice' /> (<a href=javascript:RemoveFileUpload('" + spanId + "',2,'" + json.fileName + "')>Xóa</a>)</span><br/>";
                                $("#fileQueueImageArtPrice").html(str);
                            } else {
                            }
                        },
                        'onAllComplete': function () {
                        }
                    });
            </script>
            <div id="fileQueueImageArtPrice">  
                @if (!string.IsNullOrEmpty(Model.ImageArtPrice))
                {              
                    <span id="@Model.ImageArtPrice.Replace(".","_")">@Model.ImageArtPrice<br/><input type="text" name="RedirectUrlArtPrice" id="RedirectUrlArtPrice" value="@Model.RedirectUrlArtPrice" /> (<a href="javascript:RemoveFileUpload('@Model.ImageArtPrice.Replace(".","_")',2,'@Model.ImageArtPrice')">Xóa</a>)</span><br />                
                }
            </div>
        </td>
    </tr>
    <tr>
        <td>@Html.LabelFor(m=>m.ImageAuctionCalendar)</td>
        <td>
            <input type="file" id="ipfImageAuctionCalendar"/>            
                <script type="text/javascript">
                    $('#ipfImageAuctionCalendar').uploadify({
                        'script': '/ImageWhatWeDo/UploadFile',
                        'uploader': '/Scripts/uploadify/uploadify.swf',
                        'buttonImg': '/Scripts/uploadify/btn_select.png',
                        'cancelImg': '/Scripts/uploadify/cancel.png',
                        'folder': '/SlideShow',
                        'width': '51',
                        'height': '23',
                        'fileExt': '*.jpg;*.gif;*.png;',
                        'fileDesc': '*.jpg;*.gif;*.png;',
                        'sizeLimit': '52428800',
                        'queueSizeLimit': 10,
                        'multi': false,
                        'auto': true,
                        'scriptData': { RequireUploadifySessionSync: true, SecurityToken: UploadifyAuthCookie, SessionId: UploadifySessionId },
                        'onQueueFull': function (event, queueID, fileObj) {
                        },
                        'onSelect': function (event, queueID, fileObj) {
                        },
                        'onError': function (event, queueID, fileObj, obj) {
                        },
                        'onProgress': function (event, queueID, fileObj, obj) {
                        },
                        'onComplete': function (event, queueID, fileObj, response, data) {
                            var json = eval("(" + response + ")");
                            if (json.errorCode == 100) {
                                $('#iphFileNameImageAuctionCalendar').val(json.fileName);
                                var spanId = json.fileName.replace(/\./gi, "_");
                                var str = "<span id=" + spanId + ">" + json.fileName + "<br/><input type='text' name='RedirectUrlAuctionCalendar' id='RedirectUrlAuctionCalendar' /> (<a href=javascript:RemoveFileUpload('" + spanId + "',3,'" + json.fileName + "')>Xóa</a>)</span><br/>";
                                $("#fileQueueImageAuctionCalendar").html(str);
                            } else {
                            }
                        },
                        'onAllComplete': function () {
                        }
                    });
            </script>
            <div id="fileQueueImageAuctionCalendar">  
                @if (!string.IsNullOrEmpty(Model.ImageAuctionCalendar))
                {              
                    <span id="@Model.ImageAuctionCalendar.Replace(".","_")">@Model.ImageAuctionCalendar<br/><input type="text" name="RedirectUrlAuctionCalendar" id="RedirectUrlAuctionCalendar" value="@Model.RedirectUrlAuctionCalendar" /> (<a href="javascript:RemoveFileUpload('@Model.ImageAuctionCalendar.Replace(".","_")',3,'@Model.ImageAuctionCalendar')">Xóa</a>)</span><br />                
                }
            </div>
        </td>
    </tr>    
    <tr>        
        <td>
            <input type="hidden" id="iphFileNameImageArtist" value="@Model.ImageArtist"/>
            <input type="hidden" id="iphFileNameImageArtPrice" value="@Model.ImageArtPrice"/>
            <input type="hidden" id="iphFileNameImageAuctionCalendar" value="@Model.ImageAuctionCalendar"/>           
        </td>
        <td><img class="NFButtonLeft NFh" src="/Content/Img/0.png"><input type="button" class="NFButton NFh" value="Submit" onclick="ValidateData()" /><img class="NFButtonRight NFh" src="/Content/Img/0.png"></td>
    </tr>
</table>
